package com.alonsoruibal.chess.bitboard;

public class BishopMagic {
	
	public final static long bishopMagicNumber[] =
		{0x1020041000484080L, 0x20204010a0000L, 0x8020420240000L, 0x404040085006400L,
		0x804242000000108L, 0x8901008800000L, 0x1010110400080L, 0x402401084004L,
		0x1000200810208082L, 0x20802208200L, 0x4200100102082000L, 0x1024081040020L,
		0x20210000000L, 0x8210400100L, 0x10110022000L, 0x80090088010820L,
		0x8001002480800L, 0x8102082008200L, 0x41001000408100L, 0x88000082004000L, 
		0x204000200940000L, 0x410201100100L, 0x2000101012000L, 0x40201008200c200L,
		0x10100004204200L, 0x2080020010440L, 0x480004002400L, 0x2008008008202L,
		0x1010080104000L, 0x1020001004106L, 0x1040200520800L, 0x8410000840101L,
		0x1201000200400L, 0x2029000021000L, 0x4002400080840L, 0x5000020080080080L,
		0x1080200002200L, 0x4008202028800L, 0x2080210010080L, 0x800809200008200L, 
		0x1082004001000L, 0x1080202411080L, 0x840048010101L, 0x40004010400200L,
		0x500811020800400L, 0x20200040800040L, 0x1008012800830a00L, 0x1041102001040L, 
		0x11010120200000L, 0x2020222020c00L, 0x400002402080800L, 0x20880000L,
		0x1122020400L, 0x11100248084000L, 0x210111000908000L, 0x2048102020080L, 
		0x1000108208024000L, 0x1004100882000L, 0x41044100L, 0x840400L,
		0x4208204L, 0x80000200282020cL, 0x8a001240100L, 0x2040104040080L};
	
	public final static byte bishopShiftBits[] = {
		  6, 5, 5, 5, 5, 5, 5, 6,
		  5, 5, 5, 5, 5, 5, 5, 5,
		  5, 5, 7, 7, 7, 7, 5, 5,
		  5, 5, 7, 9, 9, 7, 5, 5,
		  5, 5, 7, 9, 9, 7, 5, 5,
		  5, 5, 7, 7, 7, 7, 5, 5,
		  5, 5, 5, 5, 5, 5, 5, 5,
		  6, 5, 5, 5, 5, 5, 5, 6
		};
	
	public static long[] bishopMask;
	public static long[][] bishopMagic;
	
	static {
		GenerateBishopMagic.generateAttacks();
	}
	
	public static long getBishopAttacks(int index, long all) {
		// You are inputting the square the bishop stands on, and the position of all pieces,and getting 
				// back all the rook attacks; meaning empty squares and pieces that could be attacked
				
		int i = Gen.magicTransform(all & bishopMask[index], bishopMagicNumber[index], bishopShiftBits[index]);
		return bishopMagic[index][i];
	}
}
